package blog.service.impl;


import blog.dao.ChapterChapterCategoryDao;
import blog.pojo.ChapterChapterCategory;
import blog.service.ChapterChapterCategoryService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ChapterChapterCategoryServiceImpl implements ChapterChapterCategoryService {

    @Autowired
    private ChapterChapterCategoryDao chapterChapterCategoryDao;

    @Override
    public void edit(Integer chapterId, List<Integer> categoryIdList) throws Exception {
        ChapterChapterCategory chapterChapterCategory = new ChapterChapterCategory().setChapterId(chapterId);
        chapterChapterCategoryDao.delete(new QueryWrapper<>(chapterChapterCategory));

        for(Integer categoryId : categoryIdList){
            ChapterChapterCategory temp = new ChapterChapterCategory().setChapterId(chapterId).setChapterCategoryId(categoryId);
            chapterChapterCategoryDao.insert(temp);
        }
    }

}
